package com.changgou.order.controller;

import com.changgou.order.pojo.RemindCount;
import com.changgou.order.service.RemindCountService;
import com.changgou.util.Result;
import com.changgou.util.StatusCode;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/****
 * @Author:shenkunlin
 * @Description:
 * @Date 2019/6/14 0:18
 *****/

@RestController
@RequestMapping("/remindCount")
@CrossOrigin
public class RemindCountController {

    @Autowired
    private RemindCountService remindCountService;

    /***
     * RemindCount分页条件搜索实现
     * @param remindCount
     * @param page
     * @param size
     * @return
     */
    @PostMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@RequestBody(required = false)  RemindCount remindCount, @PathVariable  int page, @PathVariable  int size){
        //调用RemindCountService实现分页条件查询RemindCount
        PageInfo<RemindCount> pageInfo = remindCountService.findPage(remindCount, page, size);
        return new Result(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * RemindCount分页搜索实现
     * @param page:当前页
     * @param size:每页显示多少条
     * @return
     */
    @GetMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@PathVariable  int page, @PathVariable  int size){
        //调用RemindCountService实现分页查询RemindCount
        PageInfo<RemindCount> pageInfo = remindCountService.findPage(page, size);
        return new Result<PageInfo>(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * 多条件搜索品牌数据
     * @param remindCount
     * @return
     */
    @PostMapping(value = "/search" )
    public Result<List<RemindCount>> findList(@RequestBody(required = false)  RemindCount remindCount){
        //调用RemindCountService实现条件查询RemindCount
        List<RemindCount> list = remindCountService.findList(remindCount);
        return new Result<List<RemindCount>>(true,StatusCode.OK,"查询成功",list);
    }

    /***
     * 根据ID删除品牌数据
     * @param id
     * @return
     */
    @DeleteMapping(value = "/{id}" )
    public Result delete(@PathVariable String id){
        //调用RemindCountService实现根据主键删除
        remindCountService.delete(id);
        return new Result(true,StatusCode.OK,"删除成功");
    }

    /***
     * 修改RemindCount数据
     * @param remindCount
     * @param id
     * @return
     */
    @PutMapping(value="/{id}")
    public Result update(@RequestBody  RemindCount remindCount,@PathVariable String id){
        //设置主键值
        remindCount.setOrderId(id);
        //调用RemindCountService实现修改RemindCount
        remindCountService.update(remindCount);
        return new Result(true,StatusCode.OK,"修改成功");
    }

    /***
     * 新增RemindCount数据
     * @param remindCount
     * @return
     */
    @PostMapping
    public Result add(@RequestBody   RemindCount remindCount){
        //调用RemindCountService实现添加RemindCount
        remindCountService.add(remindCount);
        return new Result(true,StatusCode.OK,"添加成功");
    }

    /***
     * 根据ID查询RemindCount数据
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<RemindCount> findById(@PathVariable String id){
        //调用RemindCountService实现根据主键查询RemindCount
        RemindCount remindCount = remindCountService.findById(id);
        return new Result<RemindCount>(true,StatusCode.OK,"查询成功",remindCount);
    }

    /***
     * 查询RemindCount全部数据
     * @return
     */
    @GetMapping
    public Result<List<RemindCount>> findAll(){
        //调用RemindCountService实现查询所有RemindCount
        List<RemindCount> list = remindCountService.findAll();
        return new Result<List<RemindCount>>(true, StatusCode.OK,"查询成功",list) ;
    }
}
